﻿namespace Syngine.Components.Screens
{
	public abstract class PauseScreen : Screen
	{
		protected PauseScreen()
		{
			IsPausable = false;
			Visible = false;
		}

		protected abstract void PostDrawCore(DrawContext context);

		protected sealed override void DrawCore(DrawContext context)
		{
		}

		protected virtual void OnPauseChanged(bool paused)
		{
			if (paused)
			{
				ScreenController.Show(this);
			}
			else
			{
				Hide();
			}
		}

		protected virtual void OnPostDraw(DrawContext context)
		{
			if (Visible)
			{
				context.SpriteBatch.Begin();

				PostDrawCore(context);

				context.SpriteBatch.End();
			}
		}

		public override void Initialize()
		{
			GameState.PauseChanged += OnPauseChanged;
			GameContext.GameController.PostDraw += OnPostDraw;
			base.Initialize();
		}
	}
}